package com.lianboke.link.ad.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.lianboke.link.ad.R;
import com.lianboke.link.ad.beans.ShiPinBean;
import com.lianboke.link.ad.utils.DeviceUtils;

import java.util.List;

/**
 * 粉丝账号适配器
 * Created by admin on 2017/12/13.
 */

public class AccountAdapter extends RecyclerView.Adapter<AccountAdapter.ViewHolder> {

    private Context mContext;
    private List<ShiPinBean> mShipinDatas;
    private LayoutInflater mInflater;

    public AccountAdapter(Context context) {
        mContext = context;
        this.mInflater = LayoutInflater.from(mContext);
    }

    @Override
    public AccountAdapter.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = mInflater.inflate(R.layout.adapter_account_layout, parent, false);
        return new AccountAdapter.ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(final ViewHolder holder, final int position) {
        ShiPinBean bean = mShipinDatas.get(position);
        holder.mTvAccount.setText(bean.getAccount());
        holder.mTvCopy.setOnClickListener(new View.OnClickListener(){
            @Override
            public void onClick(View v) {
                DeviceUtils.copyContentCache(mContext,bean.getAccount());
            }
        });

    }

    @Override
    public int getItemCount() {
        return mShipinDatas == null ? 0 : mShipinDatas.size();
    }

    public void refresh(List<ShiPinBean> datas) {
        mShipinDatas = datas;
        notifyDataSetChanged();
    }

    static class ViewHolder extends RecyclerView.ViewHolder {

        TextView mTvAccount;
        TextView mTvCopy;

        public ViewHolder(View itemView) {
            super(itemView);
            mTvAccount = (TextView) itemView.findViewById(R.id.tv_name);
            mTvCopy =  (TextView)itemView.findViewById(R.id.tv_account_copy);
        }
    }
}
